package com.gm.springboot.controller;

import com.github.pagehelper.PageInfo;
import com.gm.springboot.bean.GalGame;
import com.gm.springboot.bean.Major;
import com.gm.springboot.service.GalgameService;
import com.gm.springboot.service.MajorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author Administrator
 * @Date 2020/7/2 17:21
 **/
@Controller
public class GalgameController {
    @Autowired
    GalgameService galgameService;
    @GetMapping("/galgames")
    public String findStudentAll(@RequestParam(defaultValue = "1")Integer page,
                                 @RequestParam(defaultValue = "5")Integer size,
                                 Model model
    ){
        List<GalGame> list=this.galgameService.findGalGameAll(page,size);
        PageInfo<GalGame> pageInfo=new PageInfo<>(list);
        model.addAttribute("galgames",pageInfo);
        return "galgame-list";

    }
    @GetMapping("/delGalGame/{galid}")
    public String delGalGame(@PathVariable("galid")Integer galid){
        this.galgameService.delGalGame(galid);
        return "redirect:/galgames";
    }
    @PostMapping("/addGalGame")
    public String addGalGame(GalGame galGame){
        this.galgameService.addGalGame(galGame);
        return "redirect:/galgames";
    }
    @GetMapping("/toGalGamePage/{galid}")
    public String toGalGamePage(@PathVariable("galid")Integer galid,Model model){
        GalGame galGame=this.galgameService.findGalGameById(galid);
        model.addAttribute("galgame",galGame);
        return "galgame-upd";
    }
    @PutMapping("/updGalGame")
    public String updGalGame(GalGame galGame){
        this.galgameService.updGalGame(galGame);
        return "redirect:galgames";
    }
}
